<%@ page import="com.xdwanj.util.UrlUtil" %>
<%@ page import="com.xdwanj.servlet.UserServlet" %>
<%@ page import="com.xdwanj.util.PageBean" %>
<%@ page import="java.net.URL" %>
<%@ page import="com.xdwanj.pojo.User" %>
<%@ page import="com.mysql.jdbc.StringUtils" %>
<%@ page import="com.xdwanj.util.ConstantsStr" %>
<%@ page import="com.xdwanj.pojo.Pet" %>
<%@ page import="com.xdwanj.pojo.Order" %>
<%--@elvariable id="userSession" type="com.xdwanj.pojo.User"--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/jsp/common/head.jsp" %>


<div class="container">
    <div class="row mh-content">

        <%--左边栏--%>
        <div class="col-xs-3 mh-content-left">
            <div class="mh-user-card">
                <!--个人名片-->
                <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(PageServlet.REQUEST_MAPPING, new String[]{PageServlet.POSITION, PageServlet.PWD_PAGE})%>"
                   class="thumbnail col-xs-12 mh-content-user">
                    <img class="img-rounded" src="${pageContext.request.contextPath}/img/banner.png" alt="user">
                    <div class="caption">
                        <h3 class="text-center">欢迎您！${userSession.name}</h3>
                    </div>
                </a>
            </div>

            <!--功能区-->
            <div class="mh-content-function-wrap col-xs-12">
                <ul class="nav nav-pills nav-stacked">
                    <li role="presentation" id="mh-fun-pet"><a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                     new String[]{UserServlet.METHOD, UserServlet.PET_LIST})%>"
                    >您的宠物</a></li>

                    <li role="presentation" id="mh-fun-shopping-cart"><a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                    new String[]{UserServlet.METHOD, UserServlet.SHOPPING_CART})%>"
                    >购物车</a></li>

                    <li role="presentation" id="mh-fun-order"><a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                    new String[]{UserServlet.METHOD, UserServlet.ORDER_LIST})%>"
                    >订单中心</a></li>


                    <li role="presentation"><a href="${pageContext.request.contextPath}/user?method=logout">退出登陆</a>
                    </li>
                </ul>
            </div>
        </div>

        <%--列表区--%>
        <div class="mh-content-item-wrap col-xs-9">
            <%--搜索功能--%>
            <div class="input-group col-xs-12">
                <input type="text" class="form-control" placeholder="Search for...">
                <span class="input-group-btn">
                    <button class="btn btn-default  glyphicon glyphicon-search" type="button"></button>
                </span>
            </div>

            <%--数据列表--%>
            <div class="mh-content-list-wrap">
                <div class="panel panel-default">
                    <!-- Table -->
                    <table class="table table-hover">
                        <%--@elvariable id="userFun" type="java.lang.String"--%>
                        <c:if test="${userFun != null && 'petList' eq userFun}">
                            <div class="panel-heading">您的宠物</div>

                            <thead>
                            <tr>
                                <th>#</th>
                                <th>名字</th>
                                <th>性别</th>
                                <th>年龄(月)</th>
                                <th>体重</th>
                                <th>品种</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody>
                                <%--@elvariable id="petList" type="com.xdwanj.util.PageBean"--%>
                                <%--@elvariable id="pet" type="com.xdwanj.pojo.Pet"--%>
                            <c:forEach items="${petList.content}" var="pet" varStatus="status">
                                <tr>
                                    <td scope="row">${status.index + 1}</td>
                                    <td>${pet.name}</td>
                                    <td>${pet.sex}</td>
                                    <td>${pet.age}个月</td>
                                    <td>${pet.weight}</td>
                                    <td>${pet.petType}</td>
                                    <td>${pet.info}</td>
                                    <td>
                                        <a class="glyphicon glyphicon-pencil" href="#"></a>
                                        <a class="glyphicon glyphicon glyphicon-remove"
                                           href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                           new String[]{UserServlet.METHOD, UserServlet.DEL_PET})%>&pid=${pet.id}"></a>
                                    </td>

                                </tr>
                            </c:forEach>
                            <tr><a class="btn btn-default" href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(PageServlet.REQUEST_MAPPING,
                            new String[]{PageServlet.POSITION, PageServlet.ADD_PET})%>">添加宠物</a></tr>
                            </tbody>
                        </c:if>

                        <c:if test="${userFun != null && 'shoppingCart' eq userFun}">
                            <div class="panel-heading">您的购物车</div>

                            <thead>
                            <tr>
                                <th>#</th>
                                <th>商品名</th>
                                <th>商品数目</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody>
                                <%--@elvariable id="shoppingCartList" type="com.xdwanj.util.PageBean"--%>
                                <%--@elvariable id="cartBean" type="com.xdwanj.pojo.ShoppingCart"--%>
                            <c:forEach items="${shoppingCartList.content}" var="cartBean" varStatus="status">
                                <tr>
                                    <td scope="row">${status.index + 1}</td>
                                    <td>${cartBean.commodity.name}</td>
                                    <td>${cartBean.commodityNum}</td>
                                    <td>${cartBean.addDate}</td>
                                    <td>
                                        <a class="glyphicon glyphicon-gift"
                                           href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                        new String[]{UserServlet.METHOD, UserServlet.CONVERSION})%>&scid=${cartBean.id}"></a>
                                        <a class="glyphicon glyphicon-remove"
                                           href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                           new String[]{UserServlet.METHOD, UserServlet.DEL_SHOPPING_CART})%>&scid=${cartBean.id}"></a>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </c:if>

                        <c:if test="${userFun != null && 'orderList' eq userFun}">
                            <div class="panel-heading">您的订单</div>
                            <thead>
                            <tr>
                                <th>#</th>
                                <th>商品名称</th>
                                <th>商品数量</th>
                                <th>添加时间</th>
                                <th>订单状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <%--@elvariable id="orderList" type="com.xdwanj.util.PageBean"--%>
                            <%--@elvariable id="order" type="com.xdwanj.pojo.Order"--%>
                            <c:forEach items="${orderList.content}" var="order" varStatus="status">
                                <tr>
                                    <td scope="row">${status.index + 1}</td>
                                    <td>${order.comName}</td>
                                    <td>${order.comNum}</td>
                                    <td><fmt:formatDate value="${order.ordersDate}" pattern="yyyy-MM-dd"/></td>
                                    <td>${order.state}</td>

                                    <td>

                                        <a class="glyphicon glyphicon-gift"
                                           href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                        new String[]{UserServlet.METHOD, UserServlet.CONVERSION})%>&pid=${order.id}"></a>
                                        <a class="glyphicon glyphicon-remove"
                                           href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                           new String[]{UserServlet.METHOD, UserServlet.DEL_SHOPPING_CART})%>&pid=${order.id}"></a>
                                    </td>

                                </tr>
                            </c:forEach>

                        </c:if>
                    </table>
                </div>

                <c:if test="${userFun != null && 'petList' eq userFun}"><%--@elvariable id="petList" type="com.xdwanj.util.PageBean"--%>
                    <nav>
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                new String[]{UserServlet.METHOD, UserServlet.PET_LIST})%>&currentPageNo=${petList.currentPageNo-1}"
                                   aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>

                            <c:forEach begin="1" end="${petList.totalPageCount}" varStatus="status">
                                <c:if test="${status.index == petList.currentPageNo}">
                                    <li class="active">
                                        <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                            new String[]{UserServlet.METHOD, UserServlet.PET_LIST})%>&currentPageNo=${status.index}">
                                                ${status.index}</a>
                                    </li>
                                </c:if>
                                <c:if test="${status.index != petList.currentPageNo}">
                                    <li>
                                        <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                            new String[]{UserServlet.METHOD, UserServlet.PET_LIST})%>&currentPageNo=${status.index}">
                                                ${status.index}</a>
                                    </li>
                                </c:if>
                            </c:forEach>

                            <li>
                                <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                new String[]{UserServlet.METHOD, UserServlet.PET_LIST})%>&currentPageNo=${petList.currentPageNo+1}"
                                   aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>

                        </ul>
                    </nav>
                </c:if>

                <c:if test="${userFun != null && 'shoppingCart' eq userFun}"><%--@elvariable id="shoppingCartList" type="com.xdwanj.util.PageBean"--%>
                    <nav>
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                new String[]{UserServlet.METHOD, UserServlet.SHOPPING_CART})%>&useFun=${userFun}&currentPageNo=${shoppingCartList.currentPageNo-1}"
                                   aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>

                            <c:forEach begin="1" end="${shoppingCartList.totalPageCount}" varStatus="status">
                                <c:if test="${status.index == shoppingCartList.currentPageNo}">
                                    <li class="active">
                                        <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                            new String[]{UserServlet.METHOD, UserServlet.SHOPPING_CART})%>&useFun=${userFun}&currentPageNo=${status.index}">
                                                ${status.index}</a>
                                    </li>
                                </c:if>
                                <c:if test="${status.index != shoppingCartList.currentPageNo}">
                                    <li>
                                        <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                            new String[]{UserServlet.METHOD, UserServlet.SHOPPING_CART})%>&useFun=${userFun}&currentPageNo=${status.index}">
                                                ${status.index}</a>
                                    </li>
                                </c:if>
                            </c:forEach>

                            <li>
                                <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                new String[]{UserServlet.METHOD, UserServlet.SHOPPING_CART})%>&useFun=${userFun}&currentPageNo=${shoppingCartList.currentPageNo+1}"
                                   aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>

                        </ul>
                    </nav>
                </c:if>

                <c:if test="${userFun != null && 'orderList' eq userFun}"><%--@elvariable id="orderList" type="com.xdwanj.util.PageBean"--%>
                    <nav>
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                new String[]{UserServlet.METHOD, UserServlet.ORDER_LIST})%>&currentPageNo=${orderList.currentPageNo-1}"
                                   aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>

                            <c:forEach begin="1" end="${orderList.totalPageCount}" varStatus="status">
                                <c:if test="${status.index == orderList.currentPageNo}">
                                    <li class="active">
                                        <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                            new String[]{UserServlet.METHOD, UserServlet.ORDER_LIST})%>&currentPageNo=${status.index}">
                                                ${status.index}</a>
                                    </li>
                                </c:if>
                                <c:if test="${status.index != orderList.currentPageNo}">
                                    <li>
                                        <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                            new String[]{UserServlet.METHOD, UserServlet.ORDER_LIST})%>&currentPageNo=${status.index}">
                                                ${status.index}</a>
                                    </li>
                                </c:if>
                            </c:forEach>

                            <li>
                                <a href="${pageContext.request.contextPath}<%=UrlUtil.getUrl(UserServlet.REQUEST_MAPPING,
                                new String[]{UserServlet.METHOD, UserServlet.ORDER_LIST})%>&currentPageNo=${orderList.currentPageNo+1}"
                                   aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>

                        </ul>
                    </nav>
                </c:if>
            </div>
        </div>

<%--        &lt;%&ndash;右边栏目&ndash;%&gt;--%>
<%--        <div class="mh-content-right col-xs-2">--%>
<%--            &lt;%&ndash;广告资讯&ndash;%&gt;--%>
<%--            <div class="col-xs-12 mh-content-adv-wrap">--%>
<%--                &lt;%&ndash;广告项&ndash;%&gt;--%>
<%--                <div class="mh-content-adv-item">--%>

<%--                </div>--%>
<%--                &lt;%&ndash;广告项&ndash;%&gt;--%>
<%--                <div class="mh-content-adv-item">--%>

<%--                </div>--%>
<%--                &lt;%&ndash;广告项&ndash;%&gt;--%>
<%--                <div class="mh-content-adv-item">--%>

<%--                </div>--%>
<%--            </div>--%>
<%--        </div>--%>
    </div>
</div>
<input type="hidden" id="mh-user-fun" name="user-fun" value="${userFun}">
<%@include file="/jsp/common/foot.jsp" %>
<script src="${pageContext.request.contextPath}/js/user.js"></script>